<?php require VIEWPATH . ADMIN_DIR . DIRECTORY_SEPARATOR . 'header.php' ?>
<div class="page-header">
	<h1 style="font-size: 20px;">
		<a class="a-back" href="<?= admin_url('contents/exam_data/') ?>">
            <i class="fa fa-reply"></i>
        </a>
		批次&nbsp;&nbsp;<?= $title ?>

		<!-- 同步学校不可添加数据 -->
		<?php if(! $rmxSchool['school_from']): ?>
			<a href="<?= admin_url('contents/save_exam_room_page') . '?exam_id=' . $examId ?>" class="btn btn-info a-custom">
				<i class="ace-icon fa fa-plus"></i> 添加考试
			</a>
		<?php endif ?>

	</h1>
</div>
<div class="col-xs-12">
	<!-- 同步学校不可添加数据 -->
	<?php if(! $rmxSchool['school_from']): ?>
		<!-- <a href="<?= admin_url('contents/save_exam_room_page') . '?exam_id=' . $examId ?>" class="btn btn-primary">
			<i class="ace-icon fa fa-plus"></i> 添加考试
		</a> -->
	<?php endif ?>
	<table id="dynamic-table" class="table table-striped table-bordered table-hover" style="margin-top:10px">
		<thead>
			<tr>
				<th>考试编号</th>
				<th>考试日期</th>
				<th>场次</th>
				<th>时段</th>
				<th>考试时间</th>
				<th>考试时长</th>
				<th>年级</th>
				<th>科目</th>
				<th>类型</th>
				<th>考场列表</th>
				<!-- 同步学校不可修改或删除数据 -->
				<?php if(! $rmxSchool['school_from']): ?>
					<th>操作</th>
				<?php endif ?>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
</div>

<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	var table = "";
	$(function(){
		// 考试列表
		table = $('#dynamic-table').dt({
			"ajaxUrl": '<?= admin_url('contents/get_exam_room_list/' . $examId)?>',
			"columns": [
				{"data": function(ret){
	            	return ret.id;
				}},	
				{"data": function(ret){
	            	return ret.day + '（' + ret.week + ')';
				}},	
				{"data": function(ret){
	            	return '第' + ret.timeslot + '场';
				}},
				{"data": function(ret){
	            	return ret.part_of_day;
				}},
				{"data": function(ret){
	            	return ret.begin + ' - ' + ret.end;
				}},
				{"data": function(ret){
	            	return ret.duration + '分钟';
				}},
				{"data": function(ret){
	            	return ret.grade_name;
				}},
				{"data": function(ret){
	            	return ret.lesson_name;
				}},
				{"data": function(ret){
	            	return ret.type;
				}},
				{"data": function(ret){
	            	return '<a href="<?= admin_url('contents/exam_room_detail_data/')?>' + ret.id + '" class="mr10"><i class="fa fa-gears"></i> 查看</a>';
				}},
				// 同步学校不可修改或删除数据
				<?php if(! $rmxSchool['school_from']): ?>
					{"data": function(ret){
						var action = '';
						action += '<a href="<?= admin_url('contents/save_exam_room_page?exam_id=' . $examId . '&room_id=') ?>' + ret.id + '" class="mr10 text-success"><i class="fa fa-edit"></i> 编辑</a>&nbsp;&nbsp;';
						action += '<a data-id="'+ ret.id +'" class="delete-exam-room text-danger" href="javascript:;"><i class="fa fa-times"></i> 删除</a>';
						return action;
					}},
				<?php endif ?>
			]
		});
		// 删除某场考试
		$("body").on("click", ".delete-exam-room", function(){
			var id = $(this).data("id");
			layer.confirm('确定删除考试编号：' + id + '吗？', function(){
				// 提交数据
				var postUrl = "<?=admin_url('contents/delete_exam_room_action')?>";
				var postData = {"room_id": id};
				ajax_post(postUrl, postData, function(res){
					table.draw(false);
				})
			});
		})
	})
</script>